package com.se.io;

import cn.hutool.core.date.DateTime;

import java.io.*;

public class WriteTxtFile {
    public static void main(String[] args) throws Exception {
        String filename = "D:/out.txt";

        useFileWriter(filename);
        useBufferedWriter(filename);

    }

    private static void useBufferedWriter(String filename) throws Exception {
        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(
                        new FileOutputStream(filename, true), "UTF-8"));
        writer.newLine();
        writer.write(DateTime.now().toString());
        writer.write("abc");
        writer.write("第一个");
        writer.close();

    }

    private static void useFileWriter(String filename) throws IOException {
        FileWriter fw = new FileWriter(filename,true);

        fw.write("\n");
        fw.write(DateTime.now().toString());
        fw.write("abc");
        fw.write("第二个");
        fw.close();
    }

    //        BufferedWriter writer = new BufferedWriter(
//                new OutputStreamWriter(
//                        new FileOutputStream(filename,true),"UTF-8"));

}
